<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="推广列表" name="first">
				<div>
					<div style="position: relative;display: inline-block;">
						<span>姓名：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入姓名"
							v-model="userName">
						</el-input>&nbsp;&nbsp;
					</div>
					<div style="position: relative;display: inline-block;">
						<span>电话：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入电话"
							v-model="phone">
						</el-input>&nbsp;&nbsp;
					</div>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="phoneSelect">查询
					</el-button>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleans">重置
					</el-button>&nbsp;&nbsp;
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.records">
					<el-table-column fixed prop="extensionId" label="编号" width="50">
					</el-table-column>
					<el-table-column prop="realName" label="姓名">
						<template slot-scope="scope">
							　<span style="color: #4f9dec;cursor: pointer;" @click="updatesvideo(scope.row)"
								v-text="scope.row.realName"></span>
						</template>
					</el-table-column>
					<el-table-column prop="phone" label="电话">
					</el-table-column>
					<el-table-column prop="addressDetail" label="地址">
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间">
					</el-table-column>
					<el-table-column prop="remarks" label="审核理由">
					</el-table-column>
					<el-table-column prop="createTime" label="状态">
						<template slot-scope="scope">
							<span style="color: #4f9dec;cursor: pointer;" v-if="scope.row.status == 1">待审核</span>
							<span style="color: #4f9dec;cursor: pointer;" v-if="scope.row.status == 2">已通过</span>
							<span style="color: #4f9dec;cursor: pointer;" v-if="scope.row.status == 3">已拒绝</span>
						</template>
					</el-table-column>
					<el-table-column label="操作">
						<template slot-scope="scope">  <!--  -->
							　<el-button size="mini" type="primary" v-if="scope.row.status == 1" :disabled="!isAuth('recruitList:shenhe')" @click="zhuandan(scope.row)"
								style="margin: 3px;">审核</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div style="text-align: center;margin-top: 10px;">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
						:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"
						layout="total,sizes, prev, pager, next,jumper" :total="tableData.total">
					</el-pagination>
				</div>
			</el-tab-pane>
			<!-- <el-tab-pane label="代理商列表" name="second">
				<div>
					<div style="position: relative;display: inline-block;">
						<span>姓名：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入标题名称"
							v-model="userName">
						</el-input>&nbsp;&nbsp;
					</div>
					<div style="position: relative;display: inline-block;">
						<span>电话：</span>
						<el-input style="width: 200px;" @keydown.enter.native="phoneSelect" placeholder="请输入电话"
							v-model="phone">
						</el-input>&nbsp;&nbsp;
					</div>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="phoneSelect">查询
					</el-button>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleans">重置
					</el-button>&nbsp;&nbsp;
				</div>
				<el-table v-loading="tableDataLoading" :data="tableData.list">
					<el-table-column fixed prop="id" label="编号" width="50">
					</el-table-column>
					<el-table-column prop="userName" label="姓名">
						<template slot-scope="scope">
							　<span style="color: #4f9dec;cursor: pointer;" @click="updatesvideo(scope.row)"
								v-text="scope.row.userName"></span>
						</template>
					</el-table-column>
					<el-table-column prop="phone" label="电话">
					</el-table-column>
					<el-table-column prop="city" label="地址">
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间">
					</el-table-column>
				</el-table>
				<div style="text-align: center;margin-top: 10px;">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
						:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"
						layout="total,sizes, prev, pager, next,jumper" :total="tableData.totalCount">
					</el-pagination>
				</div>
			</el-tab-pane> -->
			
			<el-dialog title="审核" :visible.sync="dialogFormVisible2" center>
				<div style="margin-bottom: 10px;">
					<span style="width: 200px;display: inline-block;text-align: right;">审核结果：</span>
					<el-radio-group v-model="status">
						<el-radio :label="2">通过</el-radio>
						<el-radio :label="3">拒绝</el-radio>
					</el-radio-group>
				</div>
				<div style="margin-bottom: 10px;" v-if="status==2">
					<span style="width: 200px;display: inline-block;text-align: right;">一级推广佣金：</span>
					<el-input style="width:50%;" v-model="divideScale" placeholder="请输入一级推广佣金分成比例（例:0.2即20%）"></el-input>
				</div>
				<div style="margin-bottom: 10px;" v-if="status==2">
					<span style="width: 200px;display: inline-block;text-align: right;">二级推广佣金：</span>
					<el-input style="width:50%;" v-model="divideTwoScale" placeholder="请输入二级推广佣金分成比例（例:0.2即20%）"></el-input>
				</div>
				
				<div style="margin-bottom: 10px;" v-if="status==3">
					<span style="width: 200px;display: inline-block;text-align: right;">审核理由：</span>
					<el-input style="width:50%;" v-model="remarks" placeholder="请输入审核理由"></el-input>
				</div>
				
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogFormVisible2 = false">取 消</el-button>
					<el-button type="primary" @click="addNoticeTo()">确 定</el-button>
				</div>
			</el-dialog>
		</el-tabs>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				tableDataLoading: true,
				tableDataLoading1: true,
				dialogFormVisible: false,
				dialogFormVisible1: false,
				dialogFormVisible2: false,
				tableData: [],
				memberName: '',
				memberImg: '',
				memberId: '',
				sort: '',
				title: '添加',
				activeName: 'first',
				classify: 1,
				userName: '',
				phone: '',
				status:'',
				extensionId:'',
				remarks:'',
				divideScale:'',
				divideTwoScale:'',
			}
		},
		methods: {
			handleClick(tab, event) {
				this.page = 1
				if (tab._props.label == '推广列表') {
					this.classify = 1
					this.dataSelect()
				}
				if (tab._props.label == '代理商列表') {
					this.classify = 2
					this.dataSelect()
				}
			},
			// 获取数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('admin/userExtension/getExtensionList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'realName': this.userName,
						'phone': this.phone,
						'status':''
						// 'classify': this.classify
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
						console.log('列表', data)
						this.tableDataLoading = false
						let returnData = data.data;
						this.tableData = returnData;
					}

				})
			},
			phoneSelect() {
				this.page = 1
				this.dataSelect()
			},
			cleans() {
				this.page = 1
				this.userName = ''
				this.phone = ''
				this.dataSelect()
			},
			//上传成功
			handleAvatarSuccess(file) {
				this.memberImg = file.data
			},
			addNotice() {
				this.status = ''
				this.remarks = ''
				this.divideScale = ''
				this.divideTwoScale = ''
				this.dialogFormVisible = true
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelect()
			},
			handleSizeChange(val) {
				this.limit = val
				this.dataSelect()
			},
			// 添加banner图
			addNoticeTo() {
				if (this.status == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请选择审核结果',
						type: 'warning'
					});
					return
				}
				if(this.status == 2){
					if (this.divideScale == '') {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: '请输入一级推广佣金',
							type: 'warning'
						});
						return
					}
					if (this.divideTwoScale == '') {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: '请输入二级推广佣金',
							type: 'warning'
						});
						return
					}
				}
				
				if(this.status == 3){
					if (this.remarks == '') {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: '请输入审核理由',
							type: 'warning'
						});
						return
					}
				}
				this.$http({
					url: this.$http.adornUrl('admin/userExtension/examine'),
					method: 'post',
					params: this.$http.adornParams({
						'status': this.status,
						'extensionId': this.extensionId,
						'remarks': this.remarks,
						'divideScale': this.divideScale,
						'divideTwoScale':this.divideTwoScale
					})
				}).then(({
					data
				}) => {
					this.dialogFormVisible2 = false
					this.$message({
						message: '操作成功',
						type: 'success',
						duration: 1500,
						onClose: () => {
							
							this.dataSelect()
						}
					})
				})
			},
			
			//删除一级
			deletes(row) {
				let delid = row.memberId
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl(`member/deleteMemberById/?memberId=${delid}`),
						method: 'post',
						data: this.$http.adornData({})
					}).then(({
						data
					}) => {
						this.$message({
							message: '删除成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.dataSelect()
							}
						})
					})
				}).catch(() => {})
			},
			
			// 详情跳转
			updatesvideo(row) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: row.userId
					}
				})
			},
			// 审核弹框
			zhuandan(row){
				this.status = ''
				this.remarks = ''
				this.divideScale = ''
				this.extensionId = row.extensionId
				this.dialogFormVisible2 = true
			}
		},
		mounted() {
			this.dataSelect()
		}
	}
</script>

<style>
</style>
